{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 使用向量计算 π的近似值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入计算精度：11522\n",
      "3.141505863102186\n"
     ]
    }
   ],
   "source": [
    "import numpy as np\n",
    "c=eval(input('请输入计算精度：'))\n",
    "verse1=np.ones(c)\n",
    "verse2=list(range(1,int(2*c+3),2))\n",
    "#print(verse2)\n",
    "a=[1,-1]\n",
    "verse3=np.tile(a,c)\n",
    "#print(verse3)\n",
    "pi=0\n",
    "for i in range(c):\n",
    "    pi += int(verse1[i])*int(verse3[i])/int(verse2[i])\n",
    "print(4*pi)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
